using System;
using System.Collections.Generic;
using System.Text;
using TNI;

namespace Graphics
{
    public class Material
    {
        #region private 

        Color ambientColor;
        double ambientFactor;
        Color diffuseColor;
        double diffuseFactor;
        Color specularColor;
        double specularFactor;
        double specularExponent;
        double reflectionFactor;
        double transmissionFactor;
        double materialIndex;

        Texture texture;
        bool hasTexture;
        //double   m_blendingFactor;

        #endregion

        public Material()
        {
            Color Ca = new Color(1, 1, 1);
            double Ka=0.2;
            Color Cd = new Color(1, 1, 1);
            double Kd=0.5;
            Color Cs = new Color(1, 1, 1);
            double Ks=0.3;
            double Ns=80;
            double Kr=0.0;
            double Kt=0.0;
            double i = 1.0;

            ambientColor = Ca;
            ambientFactor = Ka;
            diffuseColor = Cd;
            diffuseFactor = Kd;
            specularColor = Cs;
            specularFactor = Ks;
            hasTexture = false;

        }

        public Material(Color Ca)
        {
            double Ka = 0.2;
            Color Cd = new Color(1, 1, 1);
            double Kd = 0.5;
            Color Cs = new Color(1, 1, 1);
            double Ks = 0.3;
            double Ns = 80;
            double Kr = 0.0;
            double Kt = 0.0;
            double i = 1.0;

            ambientColor = Ca;
            ambientFactor = Ka;
            diffuseColor = Cd;
            diffuseFactor = Kd;
            specularColor = Cs;
            specularFactor = Ks;
            hasTexture = false;
        }

        public Material(
              Color Ca,
              double Ka,
              Color Cd,
              double Kd,
              Color Cs,
              double Ks,
              double Ns,
              double Kr,
              double Kt,
              double i
                  )
        {
              ambientColor = Ca;
              ambientFactor= Ka;
              diffuseColor= Cd;
              diffuseFactor= Kd;
              specularColor =Cs;
              specularFactor= Ks;

        }

        public Color GetAmbientColor() 
        { 
            return ambientColor * ambientFactor ;
        }

        public Color GetDiffuseColor() 
        {
            return diffuseColor * diffuseFactor;
        } 

        public Color GetSpecularColor() 
        { 
            return specularColor * specularFactor;
        }

        public void SetAmbient( double k, Color c )
        {
            ambientColor = c; 
            ambientFactor = k; 
        }

        public void SetDiffuse( double k, Color c )
        {
            diffuseColor = c; 
            diffuseFactor = k; 
        }

        public void SetSpecular( double k, double e, Color c )
        {
            specularColor = c; 
            specularFactor = k; 
            specularExponent = e; 
        }

        public void SetReflection( double f )
        {
            reflectionFactor = f; 
        }

        public void SetTransmission( double f, double i )
        {
            transmissionFactor = f; 
            materialIndex = i; 
        }

        public void SetTexture(Texture texture)
        {
            this.texture = texture;
            hasTexture = true;
        }

        public double SpecularExponent() 
        {
            return specularExponent; 
        }

        public double ReflectionFactor() 
        {
            return reflectionFactor; 
        }

        public double TransmissionFactor() 
        {
            return transmissionFactor; 
        }

        public double Index() 
        {
            return materialIndex; 
        }

        public bool HasTexture
        {
            get { return hasTexture; }
        }

        public Texture Texture
        {
            get { return this.texture; }
        }

    }
}
